package com.seas.dao;

import com.seas.domain.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;

/**
 * Created by Seas Cheng on 2017/9/29
 * reids demo
 */
@Repository
public class StudentDao {
    @Autowired  //spring boot 已经配置好stringRedisTemplate，直接注入
    StringRedisTemplate stringRedisTemplate;
    @Resource(name = "stringRedisTemplate") //使用Resource注解指定stringRedisTemplate，可注入基于字符串的简单属性操作方法
    ValueOperations<String, String> valOpsStr;
    @Autowired  //spring boot 已经配置好redisTemplate，直接注入
    RedisTemplate<Object, Object> redisTemplate;
    @Resource(name = "redisTemplate")
    ValueOperations<Object, Object> valOps;

    public void stringRedisTemplateDemo(){
        valOpsStr.set("xx","y");
    }

    public void save(Student student){
        valOps.set(student.getId(), student);
    }

    public String getString(){
        return valOpsStr.get("xx");
    }

    public Student getStudent(){
        return (Student)valOps.get("1");
    }


}
